package bb.lanxing.util.pop;

import java.util.ArrayList;
import java.util.List;

public class Task implements Comparable<Task> {
    public static final int STATUS_FAIL = 3;
    public static final int STATUS_RUNNING = 1;
    public static final int STATUS_SUCCESS = 2;
    public static final int STATUS_UN_START = 0;
    private Object object;
    private int priority;
    private int taskId;
    private TaskWork taskWork;
    private int maxTimes = 1;
    private ArrayList<PopDialog> popDialogs = new ArrayList<>();
    private int taskStatus = 0;

    public @interface TaskStatus {
    }

    public interface TaskWork {
        void onWorkInterrupt(Task task);

        void onWorkRun(Task task);
    }

    public TaskWork getTaskWork() {
        return this.taskWork;
    }

    public Task setTaskWork(TaskWork taskWork) {
        this.taskWork = taskWork;
        return this;
    }

    public void run() {
        TaskWork taskWork = this.taskWork;
        if (taskWork != null) {
            taskWork.onWorkRun(this);
        }
    }

    public int getTaskId() {
        return this.taskId;
    }

    public Task setTaskId(int i) {
        this.taskId = i;
        return this;
    }

    public int getPriority() {
        return this.priority;
    }

    public Task setPriority(int i) {
        this.priority = i;
        return this;
    }

    public int getMaxTimes() {
        return this.maxTimes;
    }

    public void setMaxTimes(int i) {
        this.maxTimes = i;
    }

    public int getTaskStatus() {
        return this.taskStatus;
    }

    public void setTaskStatus(int i) {
        this.taskStatus = i;
    }

    public Object getObject() {
        return this.object;
    }

    public Task addPopDialog(PopDialog popDialog) {
        this.popDialogs.add(popDialog);
        return this;
    }

    public Task addPopDialog(List<PopDialog> list) {
        this.popDialogs.addAll(list);
        return this;
    }

    public List<PopDialog> getPopdialogs() {
        return this.popDialogs;
    }

    public void setObject(Object obj) {
        this.object = obj;
    }

    @Override 
    public int compareTo(Task task) {
        if (this.priority > task.getPriority()) {
            return 1;
        }
        return this.priority < task.getPriority() ? -1 : 0;
    }
}
